package servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Pessoa;
import fachada.Fachada;

public class EditarPessoas extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2586528779225507951L;
	
	@Override
	protected void doPost(HttpServletRequest request, 
						  HttpServletResponse response)
						  throws ServletException, IOException {
		
		Fachada f = new Fachada();
		HttpSession session = request.getSession();
		Pessoa p = (Pessoa) session.getAttribute("pessoa");
		
		p.setNome( request.getParameter("nome") );
		p.setSobrenome( request.getParameter("sobreNome") );
		p.setDt_nascimento( request.getParameter("dataNascimento") );
		p.setEmail( request.getParameter("email") );
		p.setSenha( request.getParameter("senha") );
		
		if(f.editarPessoa(p) ){
			RequestDispatcher rd = request.getRequestDispatcher("perfil.jsp");
			rd.forward(request, response);
		}else {
			response.sendRedirect("erro_editar_conta.html");
		}
	}
	
}
